﻿using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Home.Mobilesales.Common;
using Home.MobileSales.Common.Entities;

namespace Home.MobileSales.Print
{
    public class PrintOrderTxt : PrintBuilder
    {
        public override void PrintHeader()
        {
            writer.WriteLine();
            writer.WriteLine(BuildString.CenterLine("Заявка № " + Order.NumberOrder, 80));
            writer.WriteLine();
            writer.WriteLine(Order.DateOrder.Date.ToString("dd MMMM yyyy р.").PadLeft(80));
            writer.WriteLine();
            writer.WriteLine("Покупець: " + BuyPoint.NameBuyPoint);
            writer.WriteLine("Агент: " + Settings.GetInstance().AgentName);
            writer.WriteLine();
            writer.WriteLine(BuildString.FillLine('-', 86));
            writer.Write('|' + " № ");
            writer.Write('|' + BuildString.CenterLine("Найменування", 50));
            writer.Write('|' + BuildString.CenterLine("Од.", 4));
            writer.Write('|' + BuildString.CenterLine("К-ть", 4));
            writer.Write('|' + BuildString.CenterLine("Ціна", 5));
            writer.Write('|' + BuildString.CenterLine("Сума", 9));
            writer.WriteLine('|');
            writer.WriteLine(BuildString.FillLine('-', 86));
        }

        public override void PrintBody()
        {
            int i = 1;
            foreach (OrderRecord recordOrder in Order.RecordOrders)
            {
                writer.Write('|' + i.ToString().PadLeft(3));
                writer.Write("| " + recordOrder.GoodName.PadRight(50));
                writer.Write('|' + " шт.".PadRight(5));
                writer.Write('|' + recordOrder.Quantity.ToString().PadLeft(5));
                writer.Write('|' + recordOrder.Price.ToString().PadLeft(6));
                writer.Write('|' + recordOrder.Amount.ToString().PadLeft(10));
                writer.WriteLine('|');
                writer.WriteLine(BuildString.FillLine('-', 86));
                i++;
            }
        }

        public override void PrintFooter()
        {
            writer.Write('|' + "Загальна сума".PadRight(76));
            writer.WriteLine('|' + Order.SumOrder.ToString().PadLeft(10) + "|");
            writer.WriteLine(BuildString.FillLine('-', 86));

            writer.WriteLine("\n\n\n");
            writer.WriteLine("Відпустив: ___________________");
            writer.Flush();
        }
    }
}
